<script lang="ts" setup>

import {ref, onMounted} from 'vue'
import { ElMessage } from 'element-plus'
import { Search } from '@element-plus/icons-vue'
import router from '@/router'

import{apiLogList,apiLogDetail} from "@/api/api"
import{formatOpStatus,formatBuStatus,formatOpType} from "@/utils/format"




const detailOpen = ref({
  openFlag:false,
  item:{}
})

const logList = ref([])
const reqParmas = ref({
  pageNum : 1,
  pageSize :15,
  total:0,
})


async function handleLogList(){
 const req = {
    pageNum:reqParmas.value.pageNum,
    pageSize:reqParmas.value.pageSize,
  }
  if (reqParmas.value.majorName){
    req.majorName  = reqParmas.value.majorName
  }
if (reqParmas.value.analyzeStatus){
    req.analyzeStatus  = reqParmas.value.analyzeStatus
  }
  if (reqParmas.value.standardName){
    req.standardName  = reqParmas.value.standardName
  }


  const data = await apiLogList(req)
  if (data.code != 0) {
      console.log(data)
      ElMessage.error("执行失败， 请联系管理员")
      return 
  }


  reqParmas.value.pageNum = data.pageNum
  reqParmas.value.total = data.total
  logList.value = data.rows

}

const handleDetailClick =  (item)=>{
  detailOpen.value.item = item
  detailOpen.value.openFlag =true
}

onMounted(() => {
  handleLogList()
})

</script>

<template>
<div class="info_box">

  <el-table :data="logList" style="width: 100%">
    <el-table-column prop="title" label="名称" />
    <el-table-column  prop="operUrl" label="执行名称" >
    	<template  #default="item">
        <el-text  truncated>
        	{{item.row.operUrl}}/{{item.row.operParam}}
        </el-text>
      	</template>
    </el-table-column>
    <el-table-column  prop="businessType" :formatter="formatBuStatus" label="业务类型" width='100px' />
    <el-table-column  prop="operatorType" :formatter="formatOpType" label="操作类型"  width='100px'/>
    <el-table-column  prop="operName" label="操作用户"  width='100px'/>
    <el-table-column  prop="status" label="状态" :formatter="formatOpStatus" width='100px' />
    <el-table-column  prop="operTime" label="操作时间"  width='200px'/>


    <el-table-column label="操作" width="180" >
        <template  #default="item">
          <el-button link type="primary" @click="handleDetailClick(item.row)">详情</el-button>
          <!-- <el-button link type="danger" >删除</el-button> -->
      </template>
    </el-table-column>
  </el-table>
  
  <el-pagination class='pagination' size="large" :page-size="reqParmas.pageSize" layout=" prev, pager, next, total" :total="reqParmas.total"
      v-model:current-page="reqParmas.pageNum" @current-change="handleLogList" />

</div>

  <el-dialog v-model="detailOpen.openFlag" :show-close="false"  class="box_create">
  <el-descriptions title="日志信息" :column="2">
    <el-descriptions-item label="日志名称">{{detailOpen.item.title}}</el-descriptions-item>
    <el-descriptions-item label="业务类型">
      {{formatBuStatus(detailOpen.item)}}
    </el-descriptions-item>
    <el-descriptions-item label="方法">{{detailOpen.item.operUrl}}</el-descriptions-item>
    <el-descriptions-item label="执行人">{{detailOpen.item.operName}}</el-descriptions-item>
    <el-descriptions-item label="执行IP">{{detailOpen.item.operIp}}</el-descriptions-item>
    <el-descriptions-item label="执行时间">{{detailOpen.item.operTime}}</el-descriptions-item>
    <el-descriptions-item label="方法">{{detailOpen.item.requestMethod}}:{{detailOpen.item.operUrl}}</el-descriptions-item>
    <el-descriptions-item label="参数">
          {{detailOpen.item.operParam}}
  </el-descriptions-item>
    <el-descriptions-item label="状态">      {{formatOpStatus(detailOpen.item)}}
</el-descriptions-item>
    <el-descriptions-item label="信息">{{detailOpen.item.errorMsg}}</el-descriptions-item>

  </el-descriptions>
  </el-dialog>

</template>